
#include <iostream>

#include "Window.hpp"

using namespace Gomoku::UI;

Window::Window(unsigned int width, unsigned int height) :
_width(width), _height(height),
_sfWindow(sf::VideoMode(width, height, 32), "Gomoku"),
_isOpened(true)
{
	this->_grid.generate(15, (this->_width > this->_height) ? this->_height : this->_width);
}

Window::~Window()
{
	if (this->_sfWindow.IsOpened())
		this->_sfWindow.Close();
}

bool Window::isOpened() const
{
	return this->_isOpened;
}

void Window::refresh()
{
	this->_sfWindow.Clear(sf::Color(125, 125, 125));
	this->_grid.draw(this->_sfWindow);
	this->_sfWindow.Display();
}

void Window::getEvent()
{
	sf::Event Event;
	while (this->_sfWindow.GetEvent(Event))
  {
    // Close window : exit
    if (Event.Type == sf::Event::Closed)
		{
			this->_sfWindow.Close();
			this->_isOpened = false;
		} else if (Event.Type == sf::Event::Resized) {
			this->_width = this->_sfWindow.GetWidth();
			this->_height = this->_sfWindow.GetHeight();
			std::cout <<
			this->_grid.generate(15, (this->_width > this->_height) ? this->_height : this->_width);
		}
	}
}



